
package com.example.natilocationsearch;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.uclocation.DAO.IUCLocationDAO;
import com.uclocation.DAO.UCLocationDAOStub;
import com.uclocation.DTO.UCLocation;
/*
 * @Author Angelika Our UI layer for Add
 */
public class UCLocationAdd extends Activity {
	private EditText addAddressText;
	private EditText addNicknameText; 
	private Button addtoDbBtn; 
	private IUCLocationDAO dao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uclocation_add);
		 dao = new UCLocationDAOStub(this);
		
		addAddressText = (EditText) findViewById(R.id.addAddressText);
		addNicknameText = (EditText) findViewById(R.id.addNicknameText); 
		addtoDbBtn = (Button) findViewById(R.id.addtoDbBtn); 
		
		//Create Listeners for Button
		
		OnClickListener addToDbList = new OnClickListenerAddToDb();  
		
		//Connect to Listener to Button
		
		addtoDbBtn.setOnClickListener(addToDbList); 
	
		
	}
	
	class OnClickListenerAddToDb implements OnClickListener {

		@Override
		public void onClick(View v) {
			UCLocation address = new UCLocation();
			address.setLocation(addAddressText.getText().toString());
			address.setNickName(addNicknameText.getText().toString());
			try {
				dao.addAddress(address);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.uclocation_add, menu);
		return true;
	}

}
